import 'package:casdon/core/logger/log.dart';
import 'package:casdon/core/network/business_exception.dart';

import 'package:casdon/modules/recipe/data/api/miffy_recipe_info_api.dart';
import 'package:casdon/modules/recipe/data/repository/recipe_repository.dart';
import 'package:casdon/modules/recipe/providers/recipe_provider.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

class MiffyRecipeInfoUsecase {
  final RecipeRepository _repository;

  const MiffyRecipeInfoUsecase(this._repository);

  Future<ResponseMiffyRecipeInfoApi?> execute({
    required String recipeId,
  }) async {
    try {
      final ret = await _repository.getMiffyRecipeInfo(recipeId);

      return ret;
    } on BusinessException {
      rethrow;
    } catch (e) {
      Log.e("MiffyRecipeInfoUsecase 失败", e.toString(), StackTrace.current);
      throw Exception("MiffyRecipeInfoUsecase 失败");
    }
  }
}

final miffyRecipeInfoUsecaseProvider = Provider(
  (ref) => MiffyRecipeInfoUsecase(ref.read(recipeRepository)),
);
